package com.indeep.user.demo;

import java.lang.reflect.Proxy;
import java.util.Arrays;

public class StudentProxyDemo {
    public static void main(String[] args) {
        Student student = new Student(100); // 初始余额100
        SubjectListener listener = new SubjectListener() {
            @Override
            public void onMethodCalled(String methodName, Object[] args) {
                System.out.println("Method " + methodName + " called with arguments " + Arrays.toString(args));
            }
        };
        
        StudentProxyHandler handler = new StudentProxyHandler(student, listener);
        
        StudentInterface proxyStudent = (StudentInterface) Proxy.newProxyInstance(
                StudentInterface.class.getClassLoader(),
                new Class<?>[]{StudentInterface.class}, // 注意这里传入的是接口
                handler
        );
        
        // 使用代理对象调用addMoney方法
        proxyStudent.addMoney(50);
        proxyStudent.addMoney(100);
    }
}